﻿using CgdataBase;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;

namespace FolderCompare.Models
{
    public class CgDirectoryInfo : CgFileSystemInfo
    {
        public CgDirectoryInfo() : base()
        { }

        public CgDirectoryInfo(DirectoryInfo info) : base(info)
        {
            Children = new ObservableCollection<CgFileSystemInfo>();
            foreach (var item in info.GetDirectories())
            {
                Children.Add(new CgDirectoryInfo(item));
            }

            foreach (var item in info.GetFiles())
            {
                Children.Add(new CgFileInfo(item));
            }
            IsDirectory = true;
        }

        public ObservableCollection<CgFileSystemInfo> Children { get; set; }

        public override long? Length
        {
            get
            {
                if (Children.IsNullOrEmpty())
                    return null;

                return Children.Sum(s => s.Length);
            }
        }
    }
}